﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace Nirvana
{
    public sealed class WaitLoadTexture : CustomYieldInstruction
    {
        private TextureCache texturecache;
        public Texture LoadedObject { get; private set; }
        public string Error { get; private set; }
        public WaitLoadTexture(TextureCache cache)
        {
            this.texturecache = cache;
        }


        public override bool keepWaiting
        {
            get
            {
                if (!string.IsNullOrEmpty(this.texturecache.Error))
                {
                    this.Error = this.texturecache.Error;
                    return false;
                }

                if (this.texturecache.IsNotNull())
                {
                    this.LoadedObject = this.texturecache.GetObject();
                    return false;
                }
                return true;
            }
        }


    }
}

